package cn.edu.xjtu.work.MinStack;

import java.util.Stack;

public class test {
    public static void main(String[] args) {
        test minStack = new test();
        minStack.push(512);
        minStack.push(-1024);
        minStack.push(-1024);
        minStack.push(512);
        minStack.pop();
        minStack.getMin();
        minStack.pop();
        minStack.getMin();
        minStack.pop();
        System.out.println(minStack.getMin());
    }

    Stack<Integer> dataStack;
    Stack<Integer> minStack;

    /** initialize your data structure here. */
    public test() {
        dataStack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        dataStack.push(val);
        if (minStack.empty() == true || val <= minStack.peek()) {
            minStack.push(val);
        }
    }

    // public void pop() {
    // System.out.println(dataStack.peek());
    // System.out.println(minStack.peek());
    // System.out.println(dataStack.peek() == minStack.peek());
    // System.out.println((int) dataStack.peek() == minStack.peek());
    // if (dataStack.peek().equals(minStack.peek())) {
    // minStack.pop();
    // }
    // // if (dataStack.peek() == minStack.peek()) {
    // // minStack.pop();
    // // }
    // dataStack.pop();
    // }

    public void pop() {
        int x = dataStack.pop();
        if (x == minStack.peek()) {
            minStack.pop();
        }
    }

    public int top() {
        return dataStack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
